package cn.linlane.service.sys;

import cn.linlane.dao.sys.SysRoleDao;
import cn.linlane.entity.sys.SysRole;
import cn.linlane.service.BaseService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class SysRoleService extends BaseService<SysRoleDao, SysRole> {
    /**
     * 编号查询角色
     *
     * @param id
     * @return
     */
    public SysRole findSysRoleById(Integer id){
        return baseDao.findSysRoleById(id);
    }

    /**
     * 查询ID
     *
     * @param authIds
     * @return
     */
    public Set<SysRole> findAllSysRoleById(Set<Integer> authIds){
        return baseDao.findAllByIdIn(authIds);
    }

    public Boolean existsByRoleName(String roleName){
        return baseDao.existsAllByRoleName(roleName);
    }

    /**
     * 根据部门编号和用户账户或姓名查询
     */
    public Page<SysRole> getRoles(String searchKey, Integer pageNum, Integer pageSize){
        return baseDao.fetchAllBySearchKey( searchKey, PageRequest.of(pageNum, pageSize));
    }

}
